package com.xhwl.logistics.strategy.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xhwl.common.dto.cent.vehicle.SupplierConfigDTO;
import com.xhwl.common.enums.device.DeviceActiveStatusEnum;
import com.xhwl.common.enums.device.DeviceOnlineStatusEnum;
import com.xhwl.common.enums.vehicle.CardTypeEnum;
import com.xhwl.common.enums.vehicle.ParkSupplierEnum;
import com.xhwl.common.enums.vehicle.PassageTypeEnum;
import com.xhwl.common.exception.BusinessException;
import com.xhwl.common.pojo.cent.device.Device;
import com.xhwl.common.pojo.cent.vehicle.VehcArea;
import com.xhwl.common.pojo.cent.vehicle.VehcParkingLot;
import com.xhwl.common.pojo.cent.vehicle.VehcPassage;
import com.xhwl.logistics.constant.KeyTopConstant;
import com.xhwl.logistics.dao.VehcAreaDao;
import com.xhwl.logistics.dao.VehcParkingLotDao;
import com.xhwl.logistics.strategy.InfoSyncSupplierStrategy;
import com.xhwl.logistics.util.DateFormatUtil;
import com.xhwl.logistics.util.HttpUtils;
import com.xhwl.logistics.util.SignUtils;
import com.xhwl.logistics.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.InvocationTargetException;
import java.util.*;

/**
 * @description: 信息同步科拓供应商接口
 * @author: lu.Aaron
 * @create: 2021-06-29 14:24
 **/
//@Component
@Slf4j
public class InfoSyncKeytopServiceImpl implements InfoSyncSupplierStrategy {

    @Autowired
    private VehcParkingLotDao vehcParkingLotDao;
    @Autowired
    private VehcAreaDao vehcAreaDao;
    @Override
    public int getParkSupplierId() {
        return ParkSupplierEnum.KEYTOP.supplierId;
    }

    @Override
    public List<VehcParkingLot> getParkingLotList() {
        return null;
    }


    @Override
    public VehcParkingLot getParkingLotInfo(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","getParkingLotInfo" );
        String json = generateParamJson(paramMap,appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version", version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.getParkingLotInfo, json, headerMap);
        Map parkingLotMap = JSONObject.toJavaObject(jsonResult, Map.class);
        Object data = parkingLotMap.get("data");
        Map dataMap = JSON.parseObject(data.toString(), Map.class);
        VehcParkingLot vehcParkingLot = new VehcParkingLot();
        String parkId =(String)  dataMap.get("parkId");
        String parkName = (String)dataMap.get("parkName");
        Integer totalSpaceNum = (Integer) dataMap.get("totalSpaceNum");
        vehcParkingLot.setCarSpotNum(totalSpaceNum);
        vehcParkingLot.setName(parkName);
        vehcParkingLot.setThirdParkId(parkId);
        return vehcParkingLot;

    }

    private void checkSupplierConfigDTO(SupplierConfigDTO supplierConfigDTO) {
        if (StringUtils.isBlank(supplierConfigDTO.getAppId())) {
            throw new BusinessException("配置信息无appId,请到供应商配置平台配置");
        }
        if (StringUtils.isBlank(supplierConfigDTO.getAppSecret())) {
            throw new BusinessException("配置信息无appSecret,请到供应商配置平台配置");
        }
        if (StringUtils.isBlank(supplierConfigDTO.getHost())) {
            throw new BusinessException("配置信息无host,请到供应商配置平台配置");
        }
        if (StringUtils.isBlank(supplierConfigDTO.getVersion())) {
            throw new BusinessException("配置信息无version,请到供应商配置平台配置");
        }
    }


    @Override
    public List<VehcArea> getParkingLotArea(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","getParkingPlaceArea" );
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.getParkingPlaceArea, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object data = map.get("data");
        Map dataMap = JSON.parseObject(data.toString(), Map.class);
        Object areaInfo = dataMap.get("areaInfo");
        List<Map> areaInfoMaps = JSON.parseArray(areaInfo.toString(), Map.class);

        //根据第三方parkId查询该车场信息
        String parkId = (String) paramMap.get("parkId");
        VehcParkingLot parkingLotFromDB = vehcParkingLotDao.selectOne(new QueryWrapper<VehcParkingLot>().eq("third_park_id", parkId));
        List<VehcArea> list = new ArrayList<>();

        areaInfoMaps.forEach(a->{
            StringBuilder builder = new StringBuilder();
            Integer areaCode = (Integer) a.get("areaCode");
            String areaName = (String)a.get("areaName");
            Integer placeCount = (Integer)a.get("placeCount");
            String thirdAreaId = builder.append(parkId).append("-").append(areaCode).toString();
            VehcArea vehcArea = new VehcArea();
            vehcArea.setParkingLotId(parkingLotFromDB.getId()).setThirdAreaId(thirdAreaId).setName(areaName).setCarSpotNum(placeCount);
            list.add(vehcArea);
        });
        return list;
    }

    @Override
    public List<VehcPassage> getPassageList(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","getParkingNode" );
        paramMap.put("pageSize",50);
        paramMap.put("pageIndex",1 );
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.getParkingNode, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object data = map.get("data");
        Map dataMap = JSON.parseObject(data.toString(), Map.class);
        Object nodeList = dataMap.get("nodeList");
        List<Map> nodeListMaps = JSON.parseArray(nodeList.toString(), Map.class);
        String parkId = (String) paramMap.get("parkId");
        ArrayList<String> thirdAreaIdList = new ArrayList<>();
        List<VehcPassage> list = new ArrayList<>();
        nodeListMaps.forEach(n->{
            VehcPassage vehcPassage = new VehcPassage();
            StringBuilder builderArea = new StringBuilder();
            StringBuilder builderPassage = new StringBuilder();
            Integer nodeId = (Integer) n.get("id");
            String nodeName = (String)n.get("nodeName");
            Integer useType = (Integer) n.get("useType");
            Integer areaCode = (Integer) n.get("areaCode");
            if (useType==1) {
                vehcPassage.setType(PassageTypeEnum.ENTRANCE);
            }else if (useType==2){
                vehcPassage.setType(PassageTypeEnum.EXIT);
            }else if (useType==3){
                vehcPassage.setType(PassageTypeEnum.MIDDLE_ENTRANCE);
            }else if (useType==4){
                vehcPassage.setType(PassageTypeEnum.MIDDLE_EXIT);
            }
            String thirdAreaId = builderArea.append(parkId).append("-").append(areaCode).toString();
            String thirdPassageId = builderPassage.append(parkId).append("-").append(nodeId).toString();
            thirdAreaIdList.add(thirdAreaId);
            vehcPassage.setName(nodeName).setThirdPassageId(thirdPassageId).setThirdAreaId(thirdAreaId);
            list.add(vehcPassage);
        });
        //根据thirdAreaIdList查询数据库
        List<VehcArea> listFromDB = vehcAreaDao.selectList(new QueryWrapper<VehcArea>().in("third_area_id", thirdAreaIdList));
        VehcParkingLot parkingLotFromDB = vehcParkingLotDao.selectOne(new QueryWrapper<VehcParkingLot>().eq("third_park_id", parkId));
        list.forEach(l->{
            listFromDB.forEach(lfDB->{
                StringBuilder builder = new StringBuilder();
                if (l.getThirdAreaId().equals(lfDB.getThirdAreaId())) {
                    l.setPlace(builder.append(parkingLotFromDB.getName()).append("-").append(lfDB.getName()).toString());
                    l.setAreaOrgId(lfDB.getOrgId());
                    l.setAreaId(lfDB.getId());
                }
            });
            l.setParkingLotId(parkingLotFromDB.getId());

        });

        return list;
    }

    @Override
    public List<Device> getParkingLotDevice(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","getDeviceStatus" );
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.getDeviceStatus, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object data = map.get("data");
        List<Map> maps = JSON.parseArray(data.toString(), Map.class);
        String parkId = (String) paramMap.get("parkId");
        List<Device> list = new ArrayList<>();
        maps.forEach(d->{
            Device device = new Device();
            String deviceCode=(String)d.get("deviceCode");
            String deviceName=(String)d.get("deviceName");
            //因科拓接口有问题,thirdDeviceId用parkId+ip 拼接
            String deviceIp=(String)d.get("deviceIp");
            Integer deviceStatus=(Integer)d.get("deviceStatus");
            StringBuilder builder = new StringBuilder();
            String thirdDeviceId = builder.append(parkId).append("-").append(deviceIp).toString();
            device.setThirdDeviceId(thirdDeviceId);
            device.setName(deviceName);
            if (deviceStatus.equals( DeviceOnlineStatusEnum.ONLINE.id)) {
                device.setOnlineStatus(DeviceOnlineStatusEnum.ONLINE);
            }else if (deviceStatus.equals( DeviceOnlineStatusEnum.OFFLINE.id)){
                device.setOnlineStatus(DeviceOnlineStatusEnum.OFFLINE);
            }
            device.setDeviceStatus(DeviceActiveStatusEnum.ACTIVE.id);
            device.setProductId(3);//对应设备device-product表
            device.setCategoryId(3);
            list.add(device);
        });
        return list;
    }

    @Override
    public Map addCar(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","addCarCardNo" );
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.addCarCardNo, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object resCode = map.get("resCode");
        if (!"0".equals(resCode)) {
            throw new BusinessException("科拓新增固定车接口失败");
        }
        Object data = map.get("data");
        Map dataMap = JSON.parseObject(data.toString(), Map.class);
        String cardId = String.valueOf((Integer) dataMap.get("cardId"));
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("thirdId",cardId);
        return resultMap;
    }

    @Override
    public void update(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","modifyCarCardNo" );
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.modifyCarCardNo, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object resCode = map.get("resCode");
        if (!"0".equals(resCode)) {
            throw new BusinessException("科拓修改固定车接口失败");
        }
    }

    @Override
    public Map queryCarInfo(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","getCarCardInfo" );
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.getCarCardInfo, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object resCode = map.get("resCode");
        if (!"0".equals(resCode)) {
            throw new BusinessException("科拓查询固定车接口失败");
        }
        Object data = map.get("data");
        Map dataMap = JSON.parseObject(data.toString(), Map.class);
        return dataMap;
    }

    @Override
    public void delete(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","delCarCardInfo" );
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.delCarCardNo, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object resCode = map.get("resCode");
        if (!"0".equals(resCode)) {
            throw new BusinessException("科拓删除固定车接口失败");
        }
    }

    @Override
    public List<Map> queryChargeWay(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","getCarCardRule" );
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.getCarCardRule, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object data = map.get("data");
        Map dataMap = JSON.parseObject(data.toString(), Map.class);

        if (null==dataMap) {
            throw new BusinessException("该卡类型没有收费规则");
        }

        Object ruleList = dataMap.get("ruleList");
        List<Map> ruleListMaps = JSON.parseArray(ruleList.toString(), Map.class);
        List<Map> resultList = new ArrayList<>();
        ruleListMaps.forEach(r->{
            Map<Object, Object> objectObjectHashMap = new HashMap<>();
            objectObjectHashMap.put("id",r.get("ruleId"));
            objectObjectHashMap.put("ruleName",r.get("ruleName"));
            objectObjectHashMap.put("amount",r.get("basicMoney"));
            //充值类型(0 钱(单位:分),1 月,2 天,3 小时,4次)
            //objectObjectHashMap.put("rechargeType",r.get("rechargeType"));
            //objectObjectHashMap.put("basicMoney",r.get("basicMoney"));
            resultList.add(objectObjectHashMap);
        });
        return resultList;
    }

    @Override
    public void recharge(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","payCarCardFee" );
        String cardType = (String) paramMap.get("cardType");
        //科拓系统固定车类型：0	临时车 1	VIP车 2	月租车 3	充值车 4	时租车 5	产权车 6	计次车 7	贵宾卡 8	员工卡 9	大客车 100	预约车
        if (CardTypeEnum.MONTH.getDisplay().equals(cardType)) {
            paramMap.put("carType",2);
        }else if (CardTypeEnum.STORE.getDisplay().equals(cardType)) {
            paramMap.put("carType",3);
        }else if (CardTypeEnum.FREE.getDisplay().equals(cardType)) {
            paramMap.put("carType",1);
        }
        paramMap.remove("cardType");
        paramMap.put("createTime", DateFormatUtil.date2Str(new Date(),"yyyy-MM-dd HH:mm:ss"));
        paramMap.put("remark", "无");
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.payCarCardFee, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object resCode = map.get("resCode");
        if (!"0".equals(resCode)) {
            throw new BusinessException("科拓固定车充值接口异常");
        }
    }

    @Override
    public Map tempParkFeeQuery(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","getParkingPaymentInfo" );
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.getParkingPaymentInfo, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object data = map.get("data");
        Map dataMap = JSON.parseObject(data.toString(), Map.class);
        return dataMap;
    }

    @Override
    public Map tempParkRecharge(Map<String, Object> paramMap, SupplierConfigDTO supplierConfigDTO) {
        String appId = supplierConfigDTO.getAppId();
        String appSecret = supplierConfigDTO.getAppSecret();
        String host = supplierConfigDTO.getHost();
        String version = supplierConfigDTO.getVersion();
        checkSupplierConfigDTO(supplierConfigDTO);
        paramMap.put("appId", appId);
        paramMap.put("ts", String.valueOf(System.currentTimeMillis()));
        paramMap.put("reqId", UUID.randomUUID().toString());
        paramMap.put("serviceCode","payParkingFee" );
        //应付金额
        paramMap.put("payableAmount",paramMap.get("amount"));
        //减免总金额（单位 分）
        paramMap.put("freeMoney",0 );
        //减免总时长（单位 秒）
        paramMap.put("freeTime",0 );
        String json = generateParamJson(paramMap, appSecret);
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("version",version);
        JSONObject jsonResult = HttpUtils.doPost(host + KeyTopConstant.payParkingFee, json, headerMap);
        Map map = JSONObject.toJavaObject(jsonResult, Map.class);
        Object data = map.get("data");
        Map dataMap = JSON.parseObject(data.toString(), Map.class);
        Object resCode = map.get("resCode");
        if (!"0".equals(resCode)) {
            throw new BusinessException("科拓固定车充值接口异常");
        }
        return dataMap;
    }



    /**
     * 对象转Map
     * @param obj
     * @return
     */
    private  Map<String, Object> convertToMap(Object obj) {
        try {
            if (obj instanceof Map) {
                return (Map<String, Object>)obj;
            }
            Map<String, Object> returnMap = BeanUtils.describe(obj);
            returnMap.remove("class");
            return returnMap;
        } catch (IllegalAccessException e1) {
            e1.getMessage();
        } catch (InvocationTargetException e2) {
            e2.getMessage();
        } catch (NoSuchMethodException e3) {
            e3.getMessage();
        }
        return new HashMap<>();
    }
    /**
     * 根据参数对象生成加签名的json字符串
     * @param object
     * @param appSecret
     * @return
     */
    private String generateParamJson(Object object, String appSecret) {
        String jsonString = JSON.toJSONString(object);
        JSONObject jsonObject = JSON.parseObject(jsonString);
        String key = SignUtils.paramsSign(jsonObject, appSecret);

        Map<String, Object> paramsMap = convertToMap(jsonObject);
        //参数加入签名key
        paramsMap.put("key",key);
        return JSONObject.toJSONString(paramsMap);
    }
}

